package com.net.marketing.statementcreator;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.springframework.jdbc.core.PreparedStatementCreator;
import com.net.marketing.domain.MemberDetails;

/**
 *@Author pao quilala
 *@Date   Aug 8, 2012
 **/

public class InsertMemberDetailsStatementCreator implements
		PreparedStatementCreator {
	private MemberDetails memberDetails;
	
	public InsertMemberDetailsStatementCreator(
			MemberDetails memberDetails) {
		super();
		this.memberDetails = memberDetails;
	}
	
	public PreparedStatement createPreparedStatement(Connection con)
			throws SQLException {
		String sql = "INSERT INTO MEMBER_DETAILS (SPONSOR_ID, "
				+ " GROUP_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME, "
				+ " ADDRESS, ZIPCODE, CONTACT_NO, BIRTHDATE, "
				+ " AGE, SEX, STATUS, NATIONALITY, "
				+ " DATE_CREATED, DATE_UPDATE, MEMBER_ID) "
				+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, SYSDATE, MEMBER_ID_SEQ.NEXTVAL)";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setLong(1, this.memberDetails.getSponsorId());				
		ps.setString(2, this.memberDetails.getGroupId());
		ps.setString(3, this.memberDetails.getFirstName());
		ps.setString(4, this.memberDetails.getMiddleName());
		ps.setString(5, this.memberDetails.getLastName());
		ps.setString(6, this.memberDetails.getAddress());
		ps.setString(7, this.memberDetails.getZipCode());
		ps.setString(8, this.memberDetails.getContactNo());
		ps.setDate(9, (Date) this.memberDetails.getBirthDate());
		ps.setString(10, this.memberDetails.getAge());
		ps.setString(11, this.memberDetails.getSex());
		ps.setString(12, this.memberDetails.getStatus());
		ps.setString(13, this.memberDetails.getNationality());
		return ps;
	}
}
